package de.dhbw.karlsruhe.picsim.model.commands.impl;

import de.dhbw.karlsruhe.picsim.model.actions.ActionFactory;
import de.dhbw.karlsruhe.picsim.model.actions.PicAction;
import de.dhbw.karlsruhe.picsim.model.memory.RegisterValue;
import de.dhbw.karlsruhe.picsim.model.memory.impl.RegisterValueImpl;
import de.dhbw.karlsruhe.picsim.util.Bits;
import de.dhbw.karlsruhe.picsim.util.impl.BitsMutableImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: goesen
 * Date: May 3, 2010
 * Time: 2:29:29 PM
 */
public class BTFSC extends BitSupport {
private static final Log log = LogFactory.getLog(BTFSC.class);

    public BTFSC(final Bits fileArg, final int bitArg) {
        super(fileArg, bitArg);
    }

    @Override
    protected RegisterValue doBitCommand(final RegisterValue addressedFile, final int bitArg,
                                         final List<PicAction> yourActions,
                                         final ActionFactory actionFactory) {
        log.debug("BTFSC gets executed");
        final BitsMutableImpl bits = new BitsMutableImpl(addressedFile);
        if (!bits.isSet(bitArg)) {
            yourActions.add(actionFactory.createSkipNextCommandAction());
        }
        final RegisterValue result = new RegisterValueImpl(bits);
        log.debug("result is " + result);
        return new RegisterValueImpl(bits);
    }
}
